package databases

import (
	"errors"
	"github.com/go-xorm/xorm"
	"gitlab.gaodun.com/golib/gderror"
	"permission/config"
	"permission/vigo_loger"
)

type RolesFactory struct {
	Table        Tpo_Sys_Roles
	engine       *xorm.Engine
	RowsSlicePtr []Tpo_Sys_Roles
}

// 返回 user factory
func NewRolesFactory() *RolesFactory {
	rolesFac := RolesFactory{}
	rolesFac.engine, _ = config.InitEng()
	return &rolesFac
}

func (rf *RolesFactory) FindInfoByRoleIds(roleId ...int64) error {
	if len(roleId) == 0 {
		return errors.New("role id is null")
	}
	err := rf.engine.In("RoleId", roleId).Find(&(rf.RowsSlicePtr))
	if err != nil {
		vigo_loger.AddGrayLog(gderror.New(err.Error()).Error())
	}

	return err
}

// all
func (rf *RolesFactory) FindAllInfo() error {
	err := rf.engine.Where(" 1= ? ", 1).Find(&(rf.RowsSlicePtr))
	if err != nil {
		vigo_loger.AddGrayLog(gderror.New(err.Error()).Error())
	}
	return err
}
